<?
require_once($r."_engine/c_news.php");
require_once($r."_engine/table_editor/c_table_editor.php");

class CTableEditorNews extends CTableEditor
{
	function OnPrintData($f, &$v)
	{
		if (@$f['name'] == "text")
		{
			$max_len = 50;
			if (strlen($v) > $max_len) {
				$v = substr($v, 0, $max_len);
				$v .= " ...";
			}
			$v = htmlspecialchars($v);
			$v = str_replace("\n", "<br>", $v);
			return;
		}
		
		if (@$f['name'] == "dt")
		{
			$v = date("Y-m-d H:i", $v);
			return;
		}

		$this->OnPrintDataStd($f, $v);
	}
}


$te = new CTableEditorNews();
$te->Init();
$te->table_name = "news";
$te->page_name  = "news";
$te->fields = 
	array(
		array('name'=>"id",					'title'=>"ID"),
		array('name'=>"dt",					'title'=>"Date & Time",		'type'=>"dt"),
		array('name'=>"option_is_archived",	'title'=>"Arch"),
		array('name'=>"option_show_on_fp",	'title'=>"On FP"),
		array('name'=>"title",				'title'=>"Title"),
		array('name'=>"title_fp",			'title'=>"Title on FP"),
		array('name'=>"text",				'title'=>"News body"),
	);
$te->order = "ORDER BY id DESC";
$te->st_handler = "g_st_news";

$te->buttons = array(
	$te->button_add,
	array(
		't'=>"Archive", 'ws'=>1, 'td'=>"archive",
		'conf'=>"Are you sure you want to archive selected item(s)?"
	),
	$te->button_remove
);

$te_news = $te;
?>